package com.youlu.campus.web.community.controller;

import com.youlu.campus.entity.ActivityUserAuthInfo;
import com.youlu.campus.entity.VO.res.ActivityUserAuthRes;
import com.youlu.campus.service.activity.ActivityUserAuthInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 用户活动控制器
 */
@RestController
public class UserActivityController {
    @Autowired
    private ActivityUserAuthInfoService activityUserAuthInfoService;

    /**
     * 用户活动是否验证过手机号
     *
     * @return
     */
    @PostMapping("/mini-app/user-activity/check-mobile")
    public QResult checkedMobile(@RequestParam("activityId") String activityId) {
        ActivityUserAuthRes res = new ActivityUserAuthRes();
        res.setActivityId(activityId);
        res.setUserId(RequestContext.getUserId());
        ActivityUserAuthInfo d = activityUserAuthInfoService.find(RequestContext.getUserId(), activityId);
        if (Objects.isNull(d)) {
            res.setCheckedMobile(true);
            res.setCheckedMobileTime(d.getCheckMobileTime());
        } else {
            res.setCheckedMobile(false);
        }
        return QResult.success(res);
    }
}
